package com.atguigu.search.controller;

import com.atguigu.param.ProductSearchParam;
import com.atguigu.pojo.Product;
import com.atguigu.search.service.SearchService;
import com.atguigu.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * ClassName:SearchController
 * Package:com.atguigu.search.controller
 * Description:
 *
 * @Author 应永豪
 * @Create 2024/4/22 10:36
 * @Version 1.0
 */
@RestController
@RequestMapping("search")
public class SearchController {
    @Autowired
    private SearchService searchService;

    @PostMapping("product")
    public R searchProduct(@RequestBody ProductSearchParam param) {
        return searchService.search(param);
    }

    @PostMapping("save")
    public R saveProduct(@RequestBody Product product) throws IOException {
        return searchService.saveProduct(product);
    }

    @PostMapping("remove")
    public R removeProduct(@RequestBody Integer productId) throws IOException {
        return searchService.removeProduct(productId);
    }
}
